﻿using UnityEngine;
using System.Collections;

public class RendererEnablerScript : MonoBehaviour {
	public LayerMask unitsLayer;
	public Unit unit;
	private int counter=0;
	void Update(){
		if(unit.owner==Player.Controller)return;
		if(counter++>10)
			unit.obj.renderer.enabled=false;

	}
	void OnTriggerStay(Collider other){
		if(unit.owner==Player.Controller)return;
		if((other.gameObject.layer &(~unitsLayer.value))!=0){
			if(other.transform.parent!=null){ 
				Unit u = (Unit)other.transform.parent.GetComponent("Unit");
				if(u.owner==Player.Controller){
					unit.obj.renderer.enabled=true;
					counter=0;
				}
			}
		}
	}

}
